package com.whfc.wxmp.api.base.service.impl;

import com.whfc.common.enums.AppType;
import com.whfc.common.exception.BizException;
import com.whfc.common.result.ResultEnum;
import com.whfc.fuum.dto.WxConfigDTO;
import com.whfc.fuum.service.WxConfigService;
import com.whfc.wxmp.api.base.service.WxConfigLocalService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2020-12-16 10:32
 */
@Service
public class WxConfigLocalServiceImpl implements WxConfigLocalService {

    @DubboReference(interfaceClass = WxConfigService.class, version = "1.0.0")
    private WxConfigService wxConfigService;

    @Override
    public WxConfigDTO getWxConfig(AppType appType) {
        WxConfigDTO configDTO = wxConfigService.getWxConfig(appType.name(), false);
        if (ObjectUtils.isEmpty(configDTO) || StringUtils.isEmpty(configDTO.getAppId()) || StringUtils.isEmpty(configDTO.getAppSecret())) {
            throw new BizException(ResultEnum.FAILURE.getCode(), "获取小程序配置参数错误");
        }
        return configDTO;
    }

    @Override
    public String getAccessToken(AppType appType) {
        return wxConfigService.getAccessToken(appType.name());
    }
}
